package com.yyy.dm.provider.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yyy.dm.dao.OrderMapper;
import com.yyy.dm.order.DMOrder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class OrderProviderService {

    @Resource
    private OrderMapper orderMapper;

    public Integer rollbackOrder(Long orderId){
        return orderMapper.deleteById(orderId);
    }

    public DMOrder findOrderByOrderNo(String orderNo){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("orderNo",orderNo);
        DMOrder dmOrder = orderMapper.selectOne(queryWrapper);
        return dmOrder;
    }

    public Integer updateOrder(String orderNo,String trade_no){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("orderNo",orderNo);
        DMOrder dmOrder = orderMapper.selectOne(queryWrapper);
        dmOrder.setOrderType(2);
        dmOrder.setPayType("2");
        dmOrder.setAliTradeNo(trade_no);
        return orderMapper.updateById(dmOrder);
    }

    public Integer updateOrderStatuePay(String orderNo){
        return orderMapper.updateOrderStatuePay(orderNo);
    }


    public Integer findOrderTypeById(Long id){
        return orderMapper.selectById(id).getOrderType();
    }
}
